package com.qezhhnjy.mall.coupon.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.coupon.HomeAdv;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.coupon.service.HomeAdvService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 首页轮播广告 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "首页轮播广告接口")
@Slf4j
@RequestMapping("/home-adv")
public class HomeAdvController {
    @Resource
    private HomeAdvService homeAdvService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取首页轮播广告信息")
    public BaseResult<HomeAdv> get(Long id) {
        HomeAdv homeAdv = homeAdvService.getById(id);
        return BaseResult.success(homeAdv);
    }

    @PostMapping("/save")
    @Operation(summary = "新增首页轮播广告信息")
    public BaseResult<HomeAdv> save(@RequestBody HomeAdv homeAdv) {
        homeAdvService.save(homeAdv);
        return BaseResult.success(homeAdv);
    }

    @PutMapping("/update")
    @Operation(summary = "更新首页轮播广告信息")
    public BaseResult<HomeAdv> update(@RequestBody HomeAdv homeAdv) {
        homeAdvService.updateById(homeAdv);
        return BaseResult.success(homeAdv);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取首页轮播广告信息")
    public BaseResult<Page<HomeAdv>> page(@RequestBody Page<HomeAdv> page) {
        homeAdvService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除首页轮播广告信息")
    public BaseResult<Long> delete(Long id) {
        homeAdvService.removeById(id);
        return BaseResult.success(id);
    }
}

